//Copyright (C) 2013 Julio Espindola
//
//This file is part of VSize Checkers.
//
//VSize Checkers is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//VSize Checkers is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with VSize Checkers.  If not, see <http://www.gnu.org/licenses/>.

package console;

import java.util.Scanner;

public class InputManager
{
    private static Scanner scan = new Scanner(System.in);
    
    static
    {
        scan.useDelimiter(System.getProperty("line.separator"));
    }
    
    public static String getString()
    {
        System.out.print("Input: ");
        return scan.next();
    }
    
    public static int getInt()
    { 
        System.out.print("Input: ");
            
        while(!scan.hasNextInt())
        {
            scan.next();
            System.out.println("!!! You must enter an integer (no whitespaces) !!!");
            System.out.print("Input: ");
        }

        return scan.nextInt();
    }
    
    public static int getInt(int min, int max)
    {
        int n;
        
        for(;;)
        {
            System.out.print("Input: ");
            
            while(!scan.hasNextInt())
            {
                scan.next();
                System.out.println("!!! You must enter an integer (no whitespaces)!!!");
                System.out.print("Input: ");
            }
            
            n = scan.nextInt();
            if(n >= min && n <= max) break;
            System.out.println("!!! The number must be in the range [" + min + ";" + max + "] !!!");
        }
        
        return n;
    }
    
    public static void waitForKey()
    {
        System.out.print("Press enter to continue...");
        scan.next();
    }
}
